define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'travel/index',
                    add_url: 'travel/add',
                    edit_url: 'travel/edit',
                    del_url: 'travel/del',
                    multi_url: 'travel/multi',
                    table: 'travel',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'type', title: __('Type')},
                        {field: 'user_scale', title: __('User_scale')},
                        {field: 'begintime', title: __('Begintime'), formatter: Table.api.formatter.datetime},
                        {field: 'endtime', title: __('Endtime'), formatter: Table.api.formatter.datetime},
                        {field: 'state', title: __('State')},
                        {field: 'total_fee', title: __('Total_fee')},
                        {field: 'cost', title: __('Cost')},
                        {field: 'group_num', title: __('Group_num')},
                        {field: 'limit_num', title: __('Limit_num')},
                        {field: 'memebr_price', title: __('Memebr_price')},
                        {field: 'price', title: __('Price')},
                        {field: 'other', title: __('Other')},
                        {field: 'other_fee', title: __('Other_fee')},
                        {field: 'other_desc', title: __('Other_desc')},
                        {field: 'mode', title: __('Mode')},
                        {field: 'deposit', title: __('Deposit')},
                        {field: 'qrcode', title: __('Qrcode')},
                        {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime},
                        {field: 'commission', title: __('Commission')},
                        {field: 'is_promote', title: __('Is_promote')},
                        {field: 'is_communite', title: __('Is_communite')},
                        {field: 'sponsor', title: __('Sponsor')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});